#coding=gb18030
import urllib,urllib2
import time
from pyquery import PyQuery as pq
def jiankong():
    try:
        while 1:
            bb = urllib2.urlopen('http://www.520gb.com/')
            cc = bb.getcode()
            print cc
            if cc==504:
                raise Exception('504 time out')
            #aa = urllib.urlopen('http://admin:kangle@192.168.0.39:3311/reboot')
            #print aa.read().decode('utf-8')
            #break
            time.sleep(60)
    except Exception,e:
        print 1111
        s = type(e).__name__
        t = str(e)
        if  s == 'HTTPError' and t == 'HTTP Error 504: Gateway Timeout':
            print 2222
            t1 = urllib.urlopen('http://admin:ZYQ986060@174.139.180.52:3311/reboot').read().decode('utf-8')
            t2 = pq(t1)
            urllib.urlopen('http://admin:ZYQ986060@174.139.180.52:3311%s'%t2('img').attr('src'))
        jiankong()
if __name__ =='__main__':
    jiankong()